package com.example.recognize.controller;

import com.example.recognize.config.VeificationgCode;
import com.example.recognize.entity.User;
import com.example.recognize.model.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

@RestController
@Slf4j
public class LoginController {
    @GetMapping("/hesl")
    public String hels() {
        return "尚未登录，请登录!";
    }

    @GetMapping("/login")
    public RespBean login() {
        return RespBean.error("尚未登录，请登录!");
    }


    @GetMapping("/verifyCode")
    public void verifyCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        VeificationgCode code = new VeificationgCode();
        BufferedImage image = code.getImage();
        String text = code.getText();
        HttpSession session = request.getSession(true);
        session.setAttribute("verify_code",text);
        VeificationgCode.output(image,response.getOutputStream());
    }
}
